<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>回收已完成任务的引用</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.pool.html">« Pool</a></li>
      <li style="float: right;"><a href="pool.construct.html">Pool::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.pool.html">Pool</a></li>
    <li>回收已完成任务的引用</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="pool.collect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Pool::collect</h1>
  <p class="verinfo">(PECL pthreads &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Pool::collect</span> &mdash; <span class="dc-title">回收已完成任务的引用</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pool.collect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Pool::collect</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type Callable">Callable</a></span> <code class="parameter">$collector</code><span class="initializer"> = ?</span></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   对于视为垃圾的引用，使用给定的垃圾收集器进行收集
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-pool.collect-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">collector</code></dt>

    <dd>

     <p class="para">
      垃圾收集器，它返回一个布尔值表示这个任务是否可以被进行垃圾收集。
      仅在极少的情况下需要一个自定义的垃圾收集器。
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-pool.collect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
  池中剩余的待收集的任务数量。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-pool.collect-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>v3</td>
       <td>
        <code class="parameter">collector</code> 参数变为可选参数，
        并且返回值改为整数。
       </td>
      </tr>

     </tbody>
     
   </table>

  </p>
 </div>


 
 <div class="refsect1 examples" id="refsect1-pool.collect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3342">
    <p><strong>示例 #1 <span class="methodname"><strong>Pool::collect()</strong></span> 基本用法示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$pool&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Pool</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">15</span><span style="color: #007700">;&nbsp;++</span><span style="color: #0000BB">$i</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$pool</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">submit</span><span style="color: #007700">(new&nbsp;class&nbsp;extends&nbsp;</span><span style="color: #0000BB">Threaded&nbsp;</span><span style="color: #007700">{});<br />}<br /><br />while&nbsp;(</span><span style="color: #0000BB">$pool</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collect</span><span style="color: #007700">());&nbsp;</span><span style="color: #FF8000">//&nbsp;直到全部的任务都完成执行之后才会继续下面的代码<br /><br /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">shutdown</span><span style="color: #007700">();</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>